#include "FPCH.h"

#include "FGlyph.h"

namespace Font
{

	Glyph::Glyph(Library* a_Library)
	{
		m_Library = a_Library;
		
		m_Advance.x = 0;
		m_Dimensions.x = m_Dimensions.y = 0;

		m_BitmapDimensions.x = m_BitmapDimensions.y = 0;
		m_BitmapData = NULL;
	}	

	void Glyph::SetProperties(wchar_t a_Character, const tb::Pos2& a_Position, const tb::Pos2& a_Advance)
	{
		m_Character = a_Character;
		m_Position = a_Position;
		m_Advance = a_Advance;
	}

	Glyph::~Glyph()
	{
		if (m_BitmapData) { delete [] m_BitmapData; }	
	}

	bool Glyph::CheckValid()
	{
		return (m_BitmapData != NULL || m_Advance.x > 0);
	}

	void Glyph::SetBitmap(unsigned int a_Width, unsigned int a_Height, unsigned int a_BitDepth)
	{
		m_BitmapDimensions.x = a_Width;
		m_BitmapDimensions.y = a_Height;
		m_BitmapData = new unsigned char[a_Width * a_Height * a_BitDepth];
		memset(m_BitmapData, 0, a_Width * a_Height * a_BitDepth);
	}

	void Glyph::CalculateBoundingBox()
	{
		m_BitmapArea = m_BitmapDimensions.x * m_BitmapDimensions.y;

		m_BoundingBoxStart.x = (float)m_Position.x;
		m_BoundingBoxStart.y = (float)m_Position.y;
		m_BoundingBoxEnd.x = m_BoundingBoxStart.x + (float)m_BitmapDimensions.x;
		m_BoundingBoxEnd.y = m_BoundingBoxStart.y + (float)m_BitmapDimensions.y;
	}

	bool Glyph::CheckBitmapValid()
	{
		return (m_BitmapData != NULL);
	}

	const wchar_t& Glyph::GetCharacter()
	{
		return m_Character;
	}

	unsigned int Glyph::GetBitmapArea()
	{
		return m_BitmapArea;
	}

	unsigned char* Glyph::GetBitmapData()
	{
		return m_BitmapData;
	}

}; // namespace Font